#ifndef WINDOW_H
#define WINDOW_H

#include <QtGui>
#include <QApplication>

class WLed : public QWidget
{
	Q_OBJECT
	
public: 
	WLed(QWidget *parent=0);
	enum {RED=0, GREEN, BLUE};
	enum {ON=0, FLASH, OFF};

public slots:
	void setstate(int color, int state); // ON, FLASH, OFF
	void setlightness(int color, int lightness);
	void setfreq(int color, int freq);
	void setontime(int color, int ontime);
	void setofftime(int color, int offtime);
	void loudspeaker(int freq, int num);
	void showurb(int requesttype, int request, int value, int index, int length, char *data=0);

private:
	struct {
		QPalette *palette; // set different color
		QLabel *state;
		QLabel *lightness;
		QLabel *freq;
		QLabel *onofftime;
		int ontime;
		int offtime;
	} lights[3];
	QLabel *lspker;
	QLabel *urb[4];
	char *urbmsgs[4];
};

class ReadURB : public QThread
{
	Q_OBJECT
	
	WLed* window;
	int maxurb;
	char hist[3][16]; // history urb, hist[0] is the urb before the current urb, hist[1] is the one before hist[0]
	void copewith(char buf[]);
	
public:
	ReadURB(WLed *window, int maxurb = 0, QObject* parent = NULL);
	void run();

signals:
	void setstate(int color, int state);
	void setlightness(int color, int lightness);
	void setfreq(int color, int freq);
	void setontime(int color, int ontime);
	void setofftime(int color, int offtime);
	void loudspeaker(int freq, int num);
	void showurb(int requesttype, int request, int value, int index, int length, char *data);
};

#endif
